#include "bits/stdc++.h"

using namespace std;

const int N = 2000 + 5;
const int MOD = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> PII;

#define CLEAR(x) memset(x, 0, sizeof(x))
#define MSET(x, y) memset(x, y, sizeof(x))

int t, n, m;
string s;

ll quick_pow(ll x, ll p, ll m = MOD)
{
    ll ret = 1;
    while (p)
    {
        if (p & 1)
            ret = ret * x % m;
        x = x * x % m;
        p >>= 1;
    }
    return ret;
}

int main()
{
    cin >> t;
    while (t--)
    {
        cin >> n >> m;
        int k = 0;
        for (int i = 1; i <= n; i++)
        {
            cin >> s;
            for (auto c : s)
            {
                k += (c == '#');
            }
        }

        ll res = quick_pow(2, k) - (k == n * m);
        cout << res << endl;
    }
    return 0;
}